﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BiliBiliCSharpStudy.old {
    class ParamsParammeterDemo {
        public static void demo() {
            //test1();
            test2();
        }

        public static void test2() {
            string str = "Tim;Tom,Amy.Lisa";
            // `Split` 接受 params 修饰的数组
            string[] result = str.Split(';', ',', '.');
            foreach (var item in result) {
                Console.WriteLine(item);
            }
        }

        public static void test1() {
            int[] arr = new int[] { 1, 2, 3, 4 };
            int result = CalculateSum(arr);
            Console.WriteLine(result);
            result = CalculateSum(1, 2, 3, 4);
            Console.WriteLine(result);
        }

        // params : 就是Java中的可变长参数 `...args`
        static int CalculateSum(params int[] intArray) {
            int sum = 0;
            foreach (var item in intArray) {
                sum += item;
            }
            return sum;
        }
    }
}
